package com.bootdo.common.utils;


import javax.servlet.http.HttpServletRequest;

/**
 * @author KonBAI
 * @version 1.0
 * Create by 2019/12/24 22:16
 */
public class SessionUtils {

    /**
     * 设置Session
     * @param request
     * @param key
     * @param value
     */
    public static Boolean setAttribute(HttpServletRequest request, String key, Object value) {
        try {
            request.getSession(true).setAttribute(key, value);
            return Boolean.TRUE;
        } catch (Exception e) {
            return Boolean.FALSE;
        }
    }

    /**
     * 获取Session
     * @param request
     * @param key
     * @return
     */
    public static Object getAttribute(HttpServletRequest request, String key) {
        return request.getSession(true).getAttribute(key);
    }

    /**
     * 删除Session
     * @param request
     * @param key
     */
    public static void removeAttribute(HttpServletRequest request, String key) {
        request.getSession(true).removeAttribute(key);
    }

}
